<template>
  <div class="biz-container">
    <table-layout :haveSider="false">
      <template #searchBox>
        <search-layout
          :formInfos="q_formInfos"
          :formDatas="q_formDatas"
          message="提示 : 如需修改，请到证照管理/企业证照管理中修改"
          @onChangeType="onChangeType"
          @onFind="onFind"
        ></search-layout>
      </template>
      <template #batchOperat>
        <batch-operat-btn :addData="false" @onAddData="onAddData">
          <template #cusBtn>
          </template>
        </batch-operat-btn>
      </template>
      <template #tableList="slotData">
        <a-list-table
          :columns="columns"
          :tableData="listdata"
          :pagination="pagination"
          :isSelecttion="false"
          :loading="loading"
          :scroll="{y:slotData.tableHeight}"
          @onTableChange="handleTableChange"
          @onSelect="onSelect"
          @onTouchCell="onTouchCell"
          @onAction="onAction"
        >
        </a-list-table>
      </template>
    </table-layout>
     <addLicenseModal ref="modal" @ok="handleModalSaveOk" @close="handleModalCancel" />
     <licenseImgModal ref="imgModal" :editable="true" />
     <pushCompanyLicModal ref="pushModal" @close="handlePushModalClosed"/>
  </div>
</template>

<script>
import searchLayout from '@/views/app/biz/common/searchLayout'
import batchOperatBtn from '@/views/app/biz/common/batchOperatBtn'
import tableLayout from '@/views/app/biz/common/index'
import aListInfo from '@/views/app/biz/common/aListInfo'
import aListTable from '@/views/app/biz/common/aListTable'
import licenseImgModal from '../licenseImg/licenseImgModal'
import addLicenseModal from './addLicenseModal'
import pushCompanyLicModal from './pushCompanyLicModal'
import { getByConditions, getByConditionsCount } from './companyLicense'


// 字段列表
const columns = [
  // { title: '供应商代码', dataIndex: 'dengJidwdm', key: 'dengJidwdm', align: 'center' },
  // { title: '供应商名称', dataIndex: 'dengJidwmc', key: 'dengJidwmc', align: 'center' },  

  { title: '证照类型', dataIndex: 'zhengZhaolx', width: 80, key: 'zhengZhaolx', align: 'center' },
  { title: '证照号', dataIndex: 'zhengZhaohm', key: 'zhengZhaohm', align: 'center' },
  { title: '颁发机构', dataIndex: 'banFajg', key: 'banFajg', align: 'center' },
  { title: '有效期止', dataIndex: 'youXiaoqz',key: 'youXiaoqz', align: 'center' },
  { title: '状态', dataIndex: 'zhuangTai',width: 60, key: 'zhuangTai', align: 'center',scopedSlots: { customRender: 'zhuCezZhuangtai' } },

  { title: '操作', dataIndex: 'action',width: 170, key: 'operation', align: 'center', scopedSlots: { customRender: 'action' } } ,

]

export default {
  components: {
    searchLayout,
    batchOperatBtn,
    tableLayout,
    aListInfo,
    aListTable,
    addLicenseModal,
    licenseImgModal,
    pushCompanyLicModal,
  },
  data() {
    return {
      columns: columns,
      listdata: [],
      loading: false,
      pagination: {
        //分页配置
        current: 1, //当前页码 current
        pageSize: 10, //每页显示条数 pageSize
        total: 1,
        showQuickJumper: true,
        showSizeChanger: true,
        pageSizeOptions: ['2', '10', '50', '100'],
      },
      // 查询表单
      q_formInfos: [
        { label: '证照类型', name: 'zhengZhaolx',  type: 'dicselect',dicName:'zhengZhaolx', placeholder: '证类型' },
        { label: '证照号', name: 'zhengZhaohm', type: 'input', placeholder: '证号' },
        { label: '证照状态', name: 'zhuangTai',  type: 'dicselect',dicName:'zhuCezzt', placeholder: '证照状态' },
        { label: ['查询', '重置'],   type: 'botton'},
      ],
      // 查询表单绑定数据
      q_formDatas: {
        zhuangTai: null,
        zhengZhaohm: null,
        zhengZhaolx: null,
        shengChancsmc: null
      },
      pData: {}, // 条件查询参数
    }
  },
  computed: {},
  mounted() {
    this.getTotal()
    this.getList(this.q_formDatas)
  },
  methods: {
    // 初始化页面时得到总数
    async getTotal() {
      let pages = ''
      pages = await getByConditionsCount(this.q_formDatas)
      console.log(pages)
      if (pages && pages.code && pages.code === 'C1') {
        const pagination = { ...this.pagination }
        pagination.total = pages.data
        this.pagination = pagination
        this.pagination.showTotal =  (showTotal) => {return `共 ${showTotal} 条`}
      }
    },
    // 初始化查询时的数据列表
    async getList(params) {
      console.log('请求列表时传入的数据', params)
      this.loading = true
      this.listdata = []
      let res = ''
      res = await getByConditions(params, this.pagination)
      this.loading = false
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        const resdata = res.data
         for (let item of resdata) {
            this.listdata.push({
               key: item.pid,
               action: ['推送', '推送记录'],
               ...item
               }
            )
         }
      } else {
        this.listdata = []
      }
      console.log(this.listdata)
    },
    // 新增按钮 点击了新增
    onAddData() {
      this.$refs.modal.addModal()
    },
    // 关闭模态详细框
    handleModalCancel() {
    },
    // 模态详细框提交按钮
    handleModalSaveOk() {
      this.getList(this.q_formDatas)
    },
    // 标题点击
    onTouchCell (text, record, index) {
      console.log(text)
      console.log(record)
      console.log(index)
      if (index == 'chanPinmc') {
        //编辑
        this.$refs.modal.editModal(record.pid)
      } else if (index == 'shengChancszzzt') {
        this.$refs.imgModal.showModal(record.zhengZhaotpPid)
      }
    },
    handlePushModalClosed () {
      //
    },
    // 操作按钮
    onAction(text, record) {
      if (text == '推送') {
        //编辑
        this.$refs.pushModal.showModal(record.pid)
      } else if (text == '推送记录') {
        // this.$refs.imgModal.showModal(record.zhengZhaotpPid)
      }
    },
    // 触发改变页码,筛选,排序时的回调
    handleTableChange(pagination, filters, sorter) {
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize
      this.getList(this.q_formDatas)
    },
    // 查询按钮
    onFind (){
      this.pagination.current = 1
      this.getTotal()
      this.getList(this.q_formDatas)
      this.getTotal()
    },
    // 查询条件改变时 
    onChangeType (name, val) {
      const _this = this
      // switch (name) {
      //   case 'zhengZhaolx':
      //     _this.q_formDatas.zhengZhaolx = val
      //     break
      //   case 'zhengZhaohm':
      //     _this.q_formDatas.zhengZhaohm = val
      //     break
      //   case 'shengChancsmc':
      //     _this.s_formDatas.shengChancsmc = val
      //     break
      //   case 'zhuangTai':
      //     _this.s_formDatas.zhuangTai = val
      //     break
      // }
      this.pagination.current = 1
      this.getTotal()
      this.getList(this.q_formDatas)
    },
    // 多选批量操作
    onSelect(record, selected, selectedRows) {
      console.log('onSelect', record, selected, selectedRows)
    },
  },
}
</script>
